package vip.xls8z.lfi.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(2)
@Aspect
@Component
public class OthersAspect {
    
    @Pointcut("execution(* vip.xls8z.lfi.LFIApplication.test())")
    public void targetMethod() {
        
    }
    
    @Before(value = "targetMethod()")
    public void doBefore() {
        System.out.println("OthersAspect doBefore");
    }
    
    @Around("targetMethod()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("OthersAspect doAround - before");
        Object proceed = pjp.proceed();
        System.out.println("OthersAspect doAround - after");
        return proceed;
    }
    
    @AfterReturning(value = "targetMethod()", returning = "obj")
    public Object doAfterReturning(Object obj) throws Throwable {
        System.out.println("OthersAspect doAfterReturning");
        return obj;
    }

    @AfterThrowing(value = "targetMethod()", throwing = "ex")
    public void doAfterReturning(Throwable ex) {
        System.out.println("OthersAspect doAfterReturning");
        throw new RuntimeException(ex.getMessage());
    }
}
